package common;

public class AuctionResponse implements Sendable {

	private static final long serialVersionUID = -8150639371314972702L;
	
	public final Auction responseTo;
	
	private final double price;
	private final int quantity; // Can represent ( S, QS ) or ( V, QB ) depending on whether it is a bid or ask.
	
	private final boolean notAllowed;
	
	public AuctionResponse( Auction responseTo, CommodityLimits limits, boolean notAllowed ) {
		this( responseTo, limits.bound, limits.quota, notAllowed );
	}
	
	public AuctionResponse( Auction responseTo, double price, int quantity, boolean notAllowed ) {
		this.responseTo = responseTo;
		this.price = price;
		this.quantity = quantity;
		this.notAllowed = notAllowed;
	}
	
	public boolean hasError() {
		return !responseTo.isValid(price, quantity) || notAllowed;
	}
	
	public boolean notAllowed() {
		return notAllowed;
	}
	
	public boolean invalidCommodity() {
		return responseTo.commodity == null;
	}
	
	private boolean isBid() {
		return responseTo instanceof Bid;
	}
	
	public boolean invalidBidPrice() {
		return isBid() ? ((Bid)responseTo).invalidBidPrice(price) : false;
	}
	
	public boolean invalidAskPrice() {
		return isBid() ? false : ((Ask)responseTo).invalidAskPrice(price);
	}
	
	public boolean overQuantity() {
		return responseTo.overQuantity( quantity );
	}
	
	public String getType() {
		return "AuctionResponse";
	}
	
}
